<template>
    <bi-wave-panel class="risk-people-quotas-common" :bg-color="bgColor">
        <div class="risk-people-quotas-common__main">
            <div class="risk-people-quotas-common__keynote" @click="handleKeynoteClick">
                <span class="risk-people-quotas-common__keynote-icon"><i></i></span>
                <span class="risk-people-quotas-common__keynote-value">{{data[keynote.prop]}}</span>
                <span class="risk-people-quotas-common__keynote-label">{{keynote.label}}</span>
            </div>
            <div class="risk-people-quotas-common__list">
                <div 
                    class="risk-people-quotas-common__row"
                    v-for="(row, rowIndex) in showItems"
                    :key="rowIndex"
                >
                    <div 
                        class="risk-people-quotas-common__col"
                        :class="{'is-large': col.large, 'is-link': col.click}"
                        v-for="(col, colIndex) in row"
                        :key="colIndex"
                        @click="handleColClick(col)"
                    >
                        <span class="risk-people-quotas-common__value">{{data[col.prop]}}</span>
                        <span class="risk-people-quotas-common__label">{{col.label}}</span>
                    </div>
                </div>
            </div>
        </div>
    </bi-wave-panel>
</template>
<script>
import BiWavePanel from 'board/common/wave-panel'

export default {
    name: 'RiskPeopleQuotasCommon',
    components: {
        BiWavePanel
    },
    props: {
        bgColor: {
            type: String
        },
        data: {
            type: Object,
            default: () =>({})
        },
        /**
         * 指标项集合
         * @example
         * [{
         *      label: '',
         *      prop: '',
         *      large: true
         * }]
        */
        items: {
            type: Array,
            default: () => []
        },
        /**
         * 一行显示多少列
        */
        span: {
            type: Number,
            default: 2
        }
    },
    computed: {
        keynote () {
            return this.items.slice(0, 1)[0]
        },
        showItems () {
            return this.items.slice(1).reduce((rs, v, i) => {
                const index = Math.floor(i / this.span)
                if (!rs[index]) {
                    rs[index] = []
                }
                rs[index].push(v)
                return rs
            }, [])
        }
    },
    methods: {
        handleKeynoteClick () {
            if (this.keynote && this.keynote.click) {
                this.keynote.click(this.keynote, this.data)
            }
        },
        handleColClick (col) {
            if (col.click) {
                col.click(col, this.data)
            }
        }
    }
}
</script>
<style lang="scss">
.risk-people-quotas-common{
    color: #fff;
    font-size: 18px;
    line-height: 1.5em;
    font-size: 12px;
}
.risk-people-quotas-common__keynote{
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
    padding-right: 24px;
    margin-right: 24px;
    &:after{
        content: '';
        position: absolute;
        top: 0;
        bottom: 0;
        right: 0;
        width: 1px;
        background: -moz-linear-gradient(top,  rgba(255,255,255,0) 0%, rgba(255,255,255,0.8) 25%, rgba(255,255,255,0.8) 50%, rgba(255,255,255,0.8) 75%, rgba(255,255,255,0) 100%); /* FF3.6-15 */
        background: -webkit-linear-gradient(top,  rgba(255,255,255,0) 0%,rgba(255,255,255,0.8) 25%,rgba(255,255,255,0.8) 50%,rgba(255,255,255,0.8) 75%,rgba(255,255,255,0) 100%); /* Chrome10-25,Safari5.1-6 */
        background: linear-gradient(to bottom,  rgba(255,255,255,0) 0%,rgba(255,255,255,0.8) 25%,rgba(255,255,255,0.8) 50%,rgba(255,255,255,0.8) 75%,rgba(255,255,255,0) 100%); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
        filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#00ffffff', endColorstr='#00ffffff',GradientType=0 ); /* IE6-9 */
    }
}
.risk-people-quotas-common__keynote-value,
.risk-people-quotas-common__keynote-label {
    display: block;
    margin-top: 4px;
    margin-bottom: 4px;
}
.risk-people-quotas-common__keynote-value{
    font-size: 28px;
    font-weight: bold;
}
.risk-people-quotas-common__label,
.risk-people-quotas-common__target{
    display: block;
}
.risk-people-quotas-common__row{
    display: flex;
    flex-direction: row;
    align-items: center;
    padding-top: 5px;
    padding-bottom: 5px;
    &:last-child{
        padding-bottom: 0;
    }
    &:first-child{
        padding-top: 0;
    }
}
.risk-people-quotas-common__col{
    flex: 1;
    &.is-link{
        cursor: pointer;
    }
}
.risk-people-quotas-common__value{
    font-size: 24px;
    height: 30px;
    display: block;
    line-height: 30px;
    box-sizing: content-box;
    font-weight: bold;
}
.risk-people-quotas-common__main{
    display: flex;
    flex-direction: row;
    padding: 12px 24px;
}
.risk-people-quotas-common__list{
    flex: 1;
}
.risk-people-quotas-common__keynote-icon{
    width: 44px;
    height: 44px;
    background-color: rgba(255, 255, 255, .3);
    border-radius: 50%;
    display: flex;
    flex-direction: row;
    align-items: flex-end;
    justify-content: center;
    transform: scale(.8);
    margin-bottom: 3px;
    &:after,
    &:before,
    i{
        content: '';
        display: block;
        width: 6px;
        height: 9px;
        background-color: #fff;
        margin: 0 1px 13px;
    }
    &:before{
        height: 12px;
    }
    i{
        height: 18px;
    }
}
</style>